package com.study.spark.dao.session.detail;

import java.util.ArrayList;
import java.util.List;

import com.study.spark.domain.session.detail.SessionDetail;
import com.study.spark.jdbc.JDBCHelper;

/**
 * session明细DAO实现类
 * 
 * @author Administrator
 *
 */
public class SessionDetailDaoImpl implements SessionDetailDao {

  /**
   * 插入一条session明细数据
   * 
   * @param sessionDetail
   */
  public void insert(SessionDetail sessionDetail) {
    String sql = "insert into session_detail values(?,?,?,?,?,?,?,?,?,?,?,?)";

    Object[] params = new Object[] {
        sessionDetail.getTaskid(), sessionDetail.getUserid(), sessionDetail.getSessionid(),
        sessionDetail.getPageid(), sessionDetail.getActionTime(), sessionDetail.getSearchKeyword(),
        sessionDetail.getClickCategoryId(), sessionDetail.getClickProductId(),
        sessionDetail.getOrderCategoryIds(), sessionDetail.getOrderProductIds(),
        sessionDetail.getPayCategoryIds(), sessionDetail.getPayProductIds() };

    JDBCHelper.getInstance().executeUpdate(sql, params);
  }

  /**
   * 批量插入session明细数据
   * 
   * @param sessionDetails
   */
  public void insertBatch(List<SessionDetail> sessionDetails) {
    String sql = "insert into session_detail values(?,?,?,?,?,?,?,?,?,?,?,?)";

    List<Object[]> paramsList = new ArrayList<Object[]>();
    for (SessionDetail sessionDetail : sessionDetails) {
      Object[] params = new Object[] {
          sessionDetail.getTaskid(), sessionDetail.getUserid(), sessionDetail.getSessionid(),
          sessionDetail.getPageid(), sessionDetail.getActionTime(),
          sessionDetail.getSearchKeyword(), sessionDetail.getClickCategoryId(),
          sessionDetail.getClickProductId(), sessionDetail.getOrderCategoryIds(),
          sessionDetail.getOrderProductIds(), sessionDetail.getPayCategoryIds(),
          sessionDetail.getPayProductIds() };
      paramsList.add(params);
    }

    JDBCHelper.getInstance().executeBatch(sql, paramsList);
  }

}
